from facility.contro_fn import MouseButton,KeyboardKey,InputController
from .setting import CENTER_POINT,CHAR_BOX
from .base import Base
from facility.window_fn import Window
import time
import numpy as np

DaGuai_TimeLimit = 80

import sys



class Attack(Base):
    def random_attack(self):
        time.sleep(0.5)
        targets = self.find_blood_bar()
        if targets.shape[0]:
            start = time.time()
            x,y = targets[0]
            self.move(x+self.window.x_offset,y+self.window.y_offset+30,duration=0)
            self.click(MouseButton.LEFT)
            print('\n')
            time.sleep(4)

            jingyan = self.window.snap(93,8,45,7)
            while time.time()-start<DaGuai_TimeLimit:
                diff = np.sum(self.window.snap(93,8,45,7)-jingyan)
                print('attack_time_use:',str(time.time()-start)[0:3]+" diff:"+str(diff), end='\r')
                if diff > 200:break
                time.sleep(1)
            return True
        return False


    def pick_up(self):
        start = time.time()
        time.sleep(2)
        circle = 3
        target = self.find_treasure(circle)
        print('\n')

        while target is not None and target.__len__()>0:
            print('pick_up_nm:  ',target.__len__(),end='\r')
            i = target[0]
            self.move(self.window.x_offset+i[0],self.window.y_offset+i[1]+12)
            self.click(MouseButton.LEFT)
            time.sleep(1)
            target = self.find_treasure(circle)
            time_use = time.time()-start
            if time_use > 10:
                break









